package com.im.service.dto;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class BaseException extends RuntimeException
{
  public static int INVAL_SESSION_CODE = -90001;
  public static int WRAPPED_INFO_ERR_CODE = -90002;
  private static final long serialVersionUID = 1L;
  protected int code = -90000;

  protected String id = null;

  protected String error = "RuntimeException";

  protected String message = "";

  protected Map<String, Object> datas = new HashMap<String, Object>();

  public BaseException(int code) {
    this(code, "");
  }

  public BaseException(int code, String message) {
    this(code, message, null);
  }

  public BaseException(String message) {
    this(message, null);
  }

  public BaseException(String message, Throwable cause) {
    this(-90000, message, cause);
  }

  public BaseException(int code, String message, Throwable cause) {
    super(message, cause);
    this.code = code;
    this.id = UUID.randomUUID().toString();
    this.message = message;
  }

  public int getCode() {
    return this.code;
  }

  public void setCode(int code) {
    this.code = code;
  }

  public String getError() {
    return this.error;
  }

  public void setError(String error) {
    this.error = error;
  }

  public String getMessage() {
    return this.message;
  }

  public void setMessage(String message) {
    this.message = message;
  }

  public String getId() {
    return this.id;
  }

  public void setId(String id) {
    this.id = id;
  }

  public String toString() {
    return "{'id':'" + this.id + "','error':'" + this.error + "','code':" + this.code + ",'message':'" + this.message + "'}";
  }

  public Map<String, Object> getDatas() {
    return this.datas;
  }

  public void setDatas(Map<String, Object> datas) {
    this.datas = datas;
  }

  public void addData(String name, Object data) {
    this.datas.put(name, data);
  }
}
